package OOP.Poly_Exercise.PolyExercise_Arr;

public class Test {
    public static void main(String[] args) {
        //向上转型
        Animal animal[] = new Animal[4];
        //向上转型
        animal[0] = new Cat("Cat_1");
        animal[1] = new Dog("Dog_1");
        animal[2] = new Dog("Dog_2");
        animal[3] = new Cat("Cat_2");
        for(int i=0;i<animal.length;i++){
            animal[i].cry();

            //向下转型
            if(animal[i] instanceof Dog){
                ((Dog)animal[i]).eat();
            }
            else if(animal[i] instanceof Cat){
                ((Cat)animal[i]).eat();
            }
            else{}
        }

    }
}
